<?php

// Concept based on (read: ruthlessly and mercilessly stolen from):
// Entity Data Model in "M"
// http://www.douglaspurdy.com/2009/11/25/edm-30-bring-edm-and-m-together/
// http://msdn.microsoft.com/en-us/library/ee698821%28VS.85%29.aspx

module Microsoft.Sample {

	type Person {
		Id : Integer32 => AutoNumber();
		Name : Text(50);
		Joined : DateTime;
		Addresses : Address*;
	} where identity(Id);

	type Address {
		...
	} where identity Id;

	// { as seen
	People : { Person* };

	People {
		{Name => "Brad"},
		...
	};
	// } as seen

	// {
	People : { Person* }
	{
		{Name => "Brad"},
		...
	};

}


/**

All defs and data will have to be compatible with/translatable to:
XML-RPC
PHP
JSRPC/JSON

Does NOT need to be compatible with EDM

Need to define data types:

			MySQL			XML RPC		JavaScript		EDM				C#			PHP
bool		boolean			boolean		Boolean			Boolean			bool		int
int			int(x)			int/i4		Number			Integer32		int			int
int			int(x)						Number(?)		Integer64		long		int
float		?				double		Number			Single			float		float
double		double			double		Number			Double			double		float
string		varchar(x)		string		String			Text(x)			string		string
binary		blob(?)			base64		String			?				byte[]		string

date		dt/ts			.iso8601	Date			DateTime		?
relation	fkey			array		Array			T*				List<T>
id			auto_inc..		int/i4		Number			AutoNumber()	Integer32


?: JavaScript (is|may be) limited to int32


 */





// Struct Meta ML
struct Person {
	PersonID  : Identity,
	Name      : Text(255),
	Addresses : Address*,
	Coords    : Coordinates,
}


/*
 * Compound type
 * A compound type may either reside an owning struct's table:
 * Coords:
 * table Person (
 *    PersonID char(32),
 *    Name varchar(255),
 *    Coords_Latitude double,
 *    Coords_Longitude double,
 * )
 *
 * table Person_Address (
 *    AddressID char(32),
 *    PersonID char(32),
 *
 * )
 * Addresses:
 *
 */

type Coordinates {
	Latitude  : double,
	Longitude : double,
	Altitude  : double
}

type Address {
	Street    : String,
	City      : String,
	Zip       : Integer(5, PadLeft(0)),
	Country   : String
}

JSON Representation:
{"[string PropertyName]" : +DataType, ...}
DataType is an int:
0x0001 - 0x01FF represents a bitwise type enum
0x0201 - 0x03FF represents type string, where the low 9 bits represent the string length, 1-511 bytes
var struct_person = {"PersonID":1,"Name":3,"Addresses":

_.struct.define('Person', struct_person);
_.struct('Person', {




// new javascript class: _.struct
//

// template using struct representation:

